package com.ie.controller.admin;

import com.ie.common.http.ResponseResult;
import com.ie.common.security.anno.AuthIgrone;
import com.ie.entity.CartEntity;
import com.ie.entity.GoodsEntity;
import com.ie.sevice.admin.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @classname: GoodsController
 * @Author: S2
 * @Description: //TODO
 * @Date: 2025/5/19  13:44
 * @Param:
 * @version: 1.0
 **/
@RestController
@RequestMapping("/api/admin/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    private static String fileName;
    private static byte[] filecontent;

    @AuthIgrone
    @PostMapping("/fileInit")
    public void fileInit(@RequestBody MultipartFile file) {
        // MultipartFile对象不能在另一个方法中使用，所以把文件对象变成字节数组
        try {
            filecontent = file.getBytes();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        fileName = file.getOriginalFilename();
    }
    @AuthIgrone//TODO
    @PostMapping("/add")
public ResponseResult<Map<String, String>> addGoods(@RequestBody GoodsEntity goodsEntity) {
        goodsEntity.setFileName(fileName);
        goodsEntity.setLogoFile(filecontent);
        filecontent=new byte[0];
        return goodsService.addGoods(goodsEntity);


}
    @AuthIgrone// TODO忽略权限
    @PostMapping("/getGoods")
    public ResponseResult<Map<String, Object>> getGoods(@RequestBody GoodsEntity goodsEntity) {
        return goodsService.getGoods(goodsEntity);
    }

    // 广告商品的获取
    @AuthIgrone//TODO    忽略权限
    @PostMapping("/getAdvGoods")
    public ResponseResult<List<GoodsEntity>> getAdvGoods() {
        return goodsService.getAdvGoods();
    }

    @AuthIgrone//TODO
    @PostMapping("/getGoodsById")
    public ResponseResult<GoodsEntity> getGoodsById(@RequestBody GoodsEntity goodsEntity) {
        return goodsService.getGoodsById(goodsEntity);
    }

    @AuthIgrone//TODO忽略权限
    @PostMapping("/getGoodsIndex")
    public ResponseResult<List<GoodsEntity>> getGoodsIndex(@RequestBody GoodsEntity goodsEntity) {
        return goodsService.getGoodsIndex(goodsEntity);
    }
    @AuthIgrone//TODO 忽略权限
    @PostMapping("/getGoodsByType")
    public ResponseResult<List<GoodsEntity>> getGoodsByType(@RequestBody GoodsEntity goodsEntity) {
        // return goodsService.getGoodsByType(goodsEntity);
        return null;

    }
    /**
     * @Description: 商品删除
     * @Author: S2
     * @Date: 2025/5/22  8:36
     * @Param: [goodsEntity]
     * @version: 1.0
     * @Return: com.ie.common.http.ResponseResult<java.util.Map<java.lang.String,java.lang.String>>
     **/
    @AuthIgrone//TODO 忽略权限
    @PostMapping("/delete")
    public ResponseResult<Map<String, String>> deleteGoods(@RequestBody GoodsEntity goodsEntity) {
        return goodsService.deleteGoods(goodsEntity);
    }



}
